class Document < ActiveRecord::Base
    belongs_to :source, :class_name => "Transactor", :foreign_key => "source_id"
    belongs_to :target, :class_name => "Transactor", :foreign_key => "target_id"
    belongs_to :employee
    
    has_many :positions, :class_name => "DocumentsPosition", :dependent => :destroy
    has_many :products, :through => :positions
    
	validates_presence_of :issue_date, :document_type, :number, :source_id, :target_id, :employee_id
    validates_inclusion_of :document_type, :in => %w(PZ WZ MM invoice)
	validates_uniqueness_of :number
end
